package com.d16_Socket_Homework.homework1;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class ClientDemo1_UDP {
    public static void main(String[] args) throws IOException {
        //创建发送端DatagramSocket对象
        DatagramSocket ds = new DatagramSocket();
        //键盘录入
        Scanner sc = new Scanner(System.in);
        System.out.println("发送端输入：");
        while (true) {

            String s = sc.nextLine();
            //结束判断标记
            if (s.equals("886")) {
                break;
            }
            //数据打包
            byte[] bytes = s.getBytes();
            InetAddress address = InetAddress.getByName("127.0.0.1");
            //发送的数据，数据长度，发送的ip地址，发送的目的地端口号
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length, address, 11111);
            ds.send(dp);
        }
        ds.close();
    }
}
